//
//  UIImageView+Ext.swift
//  CocoProject
//
//  Created by Vill on 2023/11/3.
//

import Foundation
import Kingfisher


extension UIImageView{
    
    func sd_setUrlImage(_ url:String?,placeholder:UIImage? = nil){
        if let imageUrl = url{
            self.kf.setImage(with: URL(string: imageUrl), placeholder: placeholder, options: nil, progressBlock: { (receivedSize, totalSize) in
            }) { (result) in
            }
        }
    }
    
    func setAvatarImage(_ url:String?){
        self.sd_setUrlImage(url, placeholder: UIImage(named: "coco_icon_holder"))
    }
}

extension UIImage{
    
    //    UIImageResizingModeStrech：拉伸模式，通过拉伸UIEdgeInsets指定的矩形区域来填充图片
    //    UIImageResizingModeTile：平铺模式，通过重复显示UIEdgeInsets指定的矩形区域来填充图片
    class func resizeWithStretchImage(_ image:UIImage) -> UIImage{
        let top    = image.size.height/2.0
        let left   = image.size.width/2.0
        let bottom = image.size.height/2.0
        let right  = image.size.width/2.0
        return image.resizableImage(withCapInsets: UIEdgeInsets(top: top, left: left, bottom: bottom, right: right), resizingMode: .stretch)
    }
    
}

